package com.xxb.web.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.xxb.constant.ResponseCode;
import com.xxb.model.entity.SysRelation;
import com.xxb.model.service.ISysRelationService;
import com.xxb.utils.DtoUtil;
import com.xxb.web.dto.ResultJson;
import com.xxb.web.dto.SysRelationDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @author 陈亮
 * @since 2018-07-07
 */
@Api(tags = "sys_relation - Controller")
@RestController
@RequestMapping("/sysRelation")
    public class SysRelationController {

    @Autowired
    private ISysRelationService isys_relationService;

    @ApiOperation(value = "添加 - sys_relation")
    @PostMapping(value = "insert")
    public ResultJson insert(@RequestBody SysRelationDto model){
        SysRelation entity=DtoUtil.convertObject(model,SysRelation.class);
        boolean flag=isys_relationService.insert(entity);
        if (flag) {
            return ResultJson.getInstance().setCode(ResponseCode.请求成功).setData(null);
        } else {
            return ResultJson.getInstance().setCode(ResponseCode.请求失败).setData(null);
        }
    }

    @ApiOperation(value = "修改 - sys_relation")
    @PutMapping(value = "up/{id}")
    public ResultJson update(@RequestBody SysRelationDto model){
    SysRelation entity=DtoUtil.convertObject(model,SysRelation.class);
        boolean flag=isys_relationService.update(entity,null);
        if (flag) {
            return ResultJson.getInstance().setCode(ResponseCode.请求成功).setData(null);
        } else {
            return ResultJson.getInstance().setCode(ResponseCode.请求失败).setData(null);
        }
    }

    @ApiOperation(value = "删除 - sys_relation")
    @DeleteMapping(value = "delete/{id}")
    public ResultJson delete(@PathVariable Integer id){
        boolean flag=isys_relationService.deleteById(id);
        if (flag) {
            return ResultJson.getInstance().setCode(ResponseCode.请求成功).setData(null);
        } else {
            return ResultJson.getInstance().setCode(ResponseCode.请求失败).setData(null);
        }
    }

    @ApiOperation(value = "查询所有 - sys_relation")
    @GetMapping(value = "query")
    public ResultJson query(){
        Page<SysRelation> page=new Page<SysRelation>();
        Page<SysRelation> list = page.setRecords(isys_relationService.selectList(null));
        return ResultJson.getInstance().setCode(ResponseCode.请求成功).setData(list);
    }


}

